package com.fx.temp.controller;

import com.fx.demo.common.resulUtils.AjaxResult;
import com.fx.temp.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class consumerHeadler {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("student/{id}")
    public AjaxResult findStudengById(@PathVariable("id") String id){
        ParameterizedTypeReference<AjaxResult<Student>> typeRef =
                new ParameterizedTypeReference<AjaxResult<Student>>(){};
        ResponseEntity<AjaxResult<Student>> responseEntity
                = restTemplate.exchange(
                        "http://localhost:8010/eurekaclient/student/{id}",
                HttpMethod.GET, null, typeRef,id);
        AjaxResult<Student>ajaxResult=responseEntity.getBody();
        return ajaxResult;
    }
}
